shell=True - the command string is interpreted as a raw shell commanduniversal_newlines=True - converts the output to a stringimport subprocess
from pprint import pprint
process = subprocess.run("ls -lha",
shell=True,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
print(process.returncode)
# 0
pprint(process.stdout.split('\n')[:5])
# ['total 2152',
# 'drwxr-xr-x 44 darrenkidney staff 1.4K 28 Jul 20:43 .',
# 'drwxr-xr-x 7 darrenkidney staff 224B 19 Jul 11:36 ..',
# '-rw-r--r--@ 1 darrenkidney staff 8.0K 19 Jul 15:21 .DS_Store',
# 'drwxr-xr-x 4 darrenkidney staff 128B 19 Jul 11:06 .Rproj.user']